{layout name="public::layout" /}
<ul class="nav nav-pills pull-left" role="tablist">
  <li>
     <button type="submit" class="btn btn-danger" form="department_form" onClick="return window.confirm('您确定删除所选记录吗？')" >删除</button>
  </li>
  <li>
      <button type="button" class="btn btn-info" onclick="history.go(0)">刷新</button>
  </li>
  <li>
      <button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal">添加</button>
  </li>
    <li>
      <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#excel">Excel导入</button>
  </li>
    <li>
      <button type="button" class="btn btn-warning"><a href="{:url('admin/Department/output')}">导出</a></button>
  </li>
    <li>
      <button type="button" class="btn btn-info" onclick="history.go(-1)">返回</button>
  </li>
</ul>
<form class="navbar-form navbar-right pull-right" action="{:url('admin/Department/searchform')}" method="post">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search" name="searchname">
        </div>
        <div class="form-group">
            <select class="form-control" name="form">
              <option value="name">名称</option>
              <option value="type">部分类型</option>
              <option value="campus">校区</option>
            </select>
    </div>
        <button type="submit" class="btn btn-default">搜索</button>
</form>
<br><br>
<h2 class="text-center text-success">部门&院系管理列表({$form}关键字：{$searchname})</h2> 

<table class="table table-hover">
    <form action="{:url('admin/Department/delete')}" method="post" id="department_form">
 <thead class="lead" >
    <tr>
        <td><input type="checkbox"  name="chkAll" onclick="chkAll_onclick(this)" />全选</td>
        <td>id</td>
        <td>名称</td>
        <td>部门类型</td>
        <td>所在校区</td>
        <td>状态</td>
        <td>权重</td>
        <td colspan="2">操作</td>
    </tr>
 </thead>
    {volist name="departmentInfo" id="department"}
    <tr>
        <td><input type="checkbox" name="ids[]" value="{$department.id}" ></td>
        <td>{$department.id}</td>
        <td>{$department.name}</td>
        <td>{$department.type}</td>
        <td>{$department.campus}</td>
        <td>
            {eq name="$department.status" value="1"}
            <span style="color:green;">启用</span>
            {else/} 
            <span style="color:red;">禁用</span>
            {/eq}
        </td>
        <td>{$department.weight}</td>
        <td>
            <a href="{:url('admin/Major/majorEdit',['id'=>$department.id])}">
                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
            </a>
        </td>      
<!--  将a标签的默认行为取消有两种方法：1，在href中写javascript:;  2,在onclick的函数后面写;return false, 建议用第二种方法-->
        <td>
            <a href="javascript:;" onClick="dele()">
                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
            </a>
        </td>       
    </tr>
    {/volist}
    </form>
</table>

<div class="text-center">{$departmentInfo|raw} </div>

<!--添加数据的模态框-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">添加数据</h4>
      </div>
      <div class="modal-body">
<!--          表单数据-->
       <form class="form-horizontal" method="post" id="login" > 
        <div class="form-group">
          <label for="name" class="col-sm-2 control-label">名称:</label>
          <div class="col-sm-8">
            <input type="text" name="name" class="form-control" id="name" placeholder="请输出名称">
          </div>
        </div>
        <div class="form-group">
          <label for="type" class="col-sm-2 control-label">部门类型:</label>
          <div class="col-sm-8">
            <input type="text" name="type" class="form-control" id="type" placeholder="请输入部门类型">
          </div>
        </div>
           <div class="form-group">
          <label for="campus" class="col-sm-2 control-label">所在校区:</label>
          <div class="col-sm-8">
            <input type="text" name="campus" class="form-control" id="campus" placeholder="请输出所在校区">
          </div>
        </div>
           <div class="form-group">
          <label for="status" class="col-sm-2 control-label">状态：</label>
            <div class="col-sm-8">
              <select class="form-control" name="status" id="status">
                  <option value="1">启用</option>
                  <option value="0">禁用</option>
                </select>
            </div>
        </div>
            <div class="form-group">
          <label for="weight" class="col-sm-2 control-label">权重:</label>
          <div class="col-sm-8">
            <input type="text" name="weight" class="form-control" id="weight" placeholder="请输入权重">
          </div>
        </div>
           <div class="form-group">
               <div class="col-sm-2">
               </div>
               <div class="col-sm-8">
                   <input type="submit" class="btn btn-primary" value="提交">
               </div>      
           </div>
      </form>
     </div>
    </div>
  </div>
</div>

<!--导入Excel的模态框-->
<div class="modal fade" id="excel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">添加数据</h4>
      </div>
      <div class="modal-body">
<!--          表单数据-->
        <form action="{:url('excel/Index/department')}" method="post" enctype="multipart/form-data">
          <div class="form-group">
            <label for="file">File input</label>
            <input type="file" id="file" name="file">
            <p class="help-block">可以选择的文件后缀为xlxs、xls、csv</p>
          </div>
          <button type="submit" class="btn btn-default">Submit</button>
        </form>
     </div>
    </div>
  </div>
</div>

<!--jquery验证数据-->
<script src="/static/jQuery_validate/lib/jquery.js"></script>
<script src="/static/jQuery_validate/lib/jquery.mockjax.js"></script>
<script src="/static/jQuery_validate/dist/jquery.validate.js"></script>


<!--a标签的响应事件-->
<script>
//    验证并ajax方式提交数据
$( "#login" ).validate({
  rules: {
    name: "required",
    type: "required",
    campus: "required",
    weight: "required",
  },
  messages:{
    major:"请输入专业名称信息",
    type:"请输入院系信息",
    campus:"请输入专业编号",
    weight:"请输入国际专业代码",
  },
    //成功的话，执行ajax数据传输
    submitHandler:function()
    {
        $.ajax({
                  type: 'POST',
                  url: "{:url('admin/Department/insertDepartment')}",
                  data: $('#login').serialize(),
                  dataType: 'json',
                  success: function(data){
                      switch(data.status)
                          {
                              case 1:
                                  alert(data.message);
                                  window.location.href="{:url('admin/Department/index')}";
                                  break;
                              case 0:          
                                  alert(data.message);
                                  window.location.href="{:url('admin/Department/index')}";
                          }
                  },
                  error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('错误');
                     }
              })
    }
});

//    删除单个
    function dele()
    {
        if(confirm('你真要删除？')==true)
            {
                window.location.href="{:url('admin/Department/doDelete',['id'=>$department.id])}";
            }
    }

//全选
    function chkAll_onclick(obj)
    {
      var chks = document.getElementsByName("ids[]");
      for( var i = 0 ; i < chks.length ; i++ )
      {
        chks[i].checked = obj.checked;
      }
    }
    

</script>